package com.star.gateway.api;

import com.star.common.core.contract.Page;
import com.star.common.core.contract.R;
import com.star.gateway.biz.DemoQueryService;
import com.star.gateway.biz.DemoService;
import com.star.gateway.contract.command.DemoDeleteCommand;
import com.star.gateway.contract.command.DemoSaveCommand;
import com.star.gateway.contract.command.DemoUpdateCommand;
import com.star.gateway.contract.query.DemoDetailQuery;
import com.star.gateway.contract.query.DemoPageQuery;
import com.star.gateway.repository.model.DemoBO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author zhouhengzhe
 * @Desc Demo仓库，主要是给人去学习用(Demo)表控制层
 * @Date 2023-12-01 17:25:30
 */
@RestController
@RequestMapping("/gateway")
@RequiredArgsConstructor
@Tag(name = "DemoController控制器")
public class DemoController {

    private final DemoService gatewayService;

    private final DemoQueryService gatewayQueryService;

    @Operation(summary = "增加gateway")
    @PostMapping(path = "/addDemo")
    public R<Void> addDemo(@RequestBody @Validated DemoSaveCommand gatewaySaveCommand) {
        gatewayService.save(gatewaySaveCommand);
        return R.ok();
    }

    @Operation(summary = "删除gateway")
    @PostMapping(path = "/removeDemo")
    public R<Void> removeDemo(@RequestBody @Validated DemoDeleteCommand gatewayDeleteCommand) {
        gatewayService.removeDemo(gatewayDeleteCommand);
        return R.ok();
    }

    @Operation(summary = "根据ID查询gateway详情")
    @PostMapping(path = "/getDemoById")
    public R<DemoBO> getDemoById(@RequestBody @Validated DemoDetailQuery gatewayDetailQuery) {
        return R.ok(gatewayQueryService.getDemoById(gatewayDetailQuery));
    }

    @Operation(summary = "修改Demo")
    @PostMapping(path = "/updateDemo")
    public R<Void> updateDemo(@RequestBody @Validated DemoUpdateCommand gatewayUpdateCommand) {
        gatewayService.updateDemo(gatewayUpdateCommand);
        return R.ok();
    }

    @Operation(summary = "条件分页查询Demo")
    @PostMapping(path = "/pageDemo")
    public R<Page<DemoBO>> pageDemo(@RequestBody DemoPageQuery gatewayPageQuery) {
        return R.ok(gatewayQueryService.pageDemo(gatewayPageQuery));
    }


}
